package com.isoft.dao.flight;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.entity.ball.Blls;
import com.isoft.entity.flight.AirportInfo;
import com.isoft.entity.flight.FlightView;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface AirportInfoDao extends BaseMapper<AirportInfo> {
    // 根据ID查询机场信息
    @Select("select META_ID,CODE,CNNM,ENNM,AISO,APSN,VALID from TEAM04.BASE_APUE where ID = #{ID}")
    AirportInfo getAirportInfoById(Integer ID);
    //查询所有机场信息
    @Select("select META_ID,CODE,CNNM,ENNM,AISO,APSN,VALID from TEAM04.BASE_APUE")
    List<AirportInfo> getAllAirportInfo();

    //根据航班号查询机场信息
//    @Select("select ID,META_ID,CODE,CNNM,ENNM,AISO,APSN from TEAM04.BASE_APUE where META_ID = #{METAID}")
    @Select("    <script>        SELECT  " +
            "           ID,META_ID,CODE,CNNM,ENNM,AISO,APSN,VALID  " +
            "        FROM  " +
            "            TEAM04.BASE_APUE  " +
            "        <where> " +
            "            <if test=\" META_ID != null and META_ID != ''\"> " +
            "                AND META_ID LIKE CONCAT('%', #{METAID}, '%') " +
            "            </if> " +
            "            <if test=\"CNNM != null and CNNM != ''\"> " +
            "                AND CNNM LIKE CONCAT('%', #{CNNM}, '%') " +
            "            </if> " +
            "            <if test=\"ENNM != null and ENNM != ''\"> " +
            "                AND ENNM LIKE CONCAT('%', #{ENNM}, '%') " +
            "            </if> " +
            "        </where> " +
            "    </script>")
    List<AirportInfo> getAirportInfoBy(@Param("METAID") Integer METAID,@Param("CNNM") String CNNM,@Param("ENNM") String ENNM);

    //分页查询
    @Override
    List<AirportInfo> selectList(Wrapper<AirportInfo> queryWrapper);

    //增加航班机场信息
    @Insert("insert into TEAM04.BASE_APUE(META_ID,CODE,CNNM,ENNM,AISO,APSN) " +
            "values(#{META_ID},#{CODE},#{CNNM},#{ENNM},#{AISO},#{APSN})")
    int insert(AirportInfo airportInfo);


    // 删除
    int deleteById(Integer ID);

    //修改
    @Update("<script>UPDATE TEAM04.BASE_APUE " +
            "<set>" +
            "<if test='META_ID != null'>META_ID = #{METAID},</if>" +
            "<if test='CODE != null'>CODE = #{CODE},</if>" +
            "<if test='CNNM != null'>CNNM = #{CNNM},</if>" +
            "<if test='ENNM != null'>ENNM = #{ENNM},</if>" +
            "<if test='AISO != null'>AISO = #{AISO},</if>" +
            "<if test='APSN != null'>APSN = #{APSN},</if>" +
            "<if test='VALID != null'>VALID = #{VALID},</if>" +
            "</set>" +
            "WHERE ID = #{ID}</script>")
    int updateById(AirportInfo airportInfo);
}
